package cn.seqdata.rpt.pivot;

import java.util.Comparator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Table;
import com.google.common.collect.Table.Cell;
import com.google.common.collect.TreeBasedTable;

public class PivotTable<R, C> {
	@JsonIgnore
	public final Table<R, C, Number> table;
	public final Map<R, String> rows;
	public final Map<C, String> cols;

	public PivotTable(Table<R, C, Number> table) {
		rows = new TreeMap<>();
		cols = new TreeMap<>();
		this.table = table;
	}

	public PivotTable(Comparator<R> rowComparator, Comparator<C> colComparator) {
		rows = new TreeMap<>(rowComparator);
		cols = new TreeMap<>(colComparator);
		table = TreeBasedTable.create(rowComparator, colComparator);
	}

	public Set<Cell<R, C, Number>> getCells() {
		return table.cellSet();
	}
}
